package com.bolt.report.business.modules.link.service;

import com.bolt.convention.data.code.CommonCode;
import com.bolt.convention.exception.ServiceException;
import com.bolt.report.business.modules.link.dto.ReportLinkDTO;
import com.bolt.report.business.modules.link.dto.converter.ReportLinkConverter;
import com.bolt.report.business.modules.link.entity.ReportLinkEntity;
import com.bolt.report.business.modules.link.repository.ReportLinkRepository;
import com.bolt.support.base.service.BaseService;
import com.bolt.support.spring.jpa.repository.BasicJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Auto Generate Javadoc
* @author
* 日期:2023-03-30 16:17:07
* 超链接配置表
**/
@Service
@Transactional(readOnly = true,rollbackFor = Exception.class)
@RequiredArgsConstructor
public class  ReportLinkService extends BaseService<ReportLinkEntity, String>{
    
    private final ReportLinkRepository reportLinkRepository;

    @Override
    protected BasicJpaRepository<ReportLinkEntity, String> getRepository() {
        return reportLinkRepository;
    }

    @Transactional(rollbackFor = Exception.class)
    public ReportLinkEntity saveOrUpdate( ReportLinkDTO dto) {
        ReportLinkEntity entity =  findOne(dto.getId()).orElseThrow(()->new ServiceException(CommonCode.DATA_NOT_FOUND));
        ReportLinkConverter.toEntity(entity,dto);
        return save(entity);
    }
}
